package 题目集.线段树or树状数组.线段树;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

/**
 * 有类似的模板：https://www.luogu.com.cn/problem/P1253
 * 对数器验证
 * 存在加法和重置的线段树.
 * 重置操作会覆盖掉之前的加法操作
 */
public class ch03_综合模板_求区间最大值 {

    static Node[] tr;
    static long[] src;
    static int n, m, tn;

    public static void main(String[] args) {
        Reader2 sc = new Reader2();
        n = sc.nextInt();
        m = sc.nextInt();
        tn = (int) Math.pow(2, Math.ceil(Math.log(n) / Math.log(2)) + 1);
        src = new long[n + 1];
        tr = new Node[tn];
        for (int i = 1; i < src.length; i++) {
            src[i] = sc.nextInt();
        }
        build(1, 1, n);
        while (m-- > 0) {
            int op = sc.nextInt();
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (op == 1) {
                update(1, l, r, sc.nextInt());
            } else if (op == 2) {
                add(1, l, r, sc.nextInt());
            } else {
                long query = query(1, l, r);
                Reader2.pw.println(query);
            }
        }
        Reader2.pw.flush();
    }

    public static void build(int i, int l, int r) {
        tr[i] = new Node(l, r);
        if (l == r) {
            tr[i].val = src[l];
            return;
        }
        int m = l + r >> 1;
        build(i << 1, l, m);
        build(i << 1 | 1, m + 1, r);
        pull(i);
    }

    public static void add(int i, int l, int r, long v) {
        if (l <= tr[i].l && tr[i].r <= r) {
            addLazy(i, v);
            return;
        }
        push(i);
        int m = tr[i].l + tr[i].r >> 1;
        if (l <= m) {
            add(i << 1, l, r, v);
        }
        if (m < r) {
            add(i << 1 | 1, l, r, v);
        }
        pull(i);
    }

    public static void update(int i, int l, int r, long v) {
        if (l <= tr[i].l && tr[i].r <= r) {
            updateLazy(i, v);
            return;
        }
        push(i);
        int m = tr[i].l + tr[i].r >> 1;
        if (l <= m) {
            update(i << 1, l, r, v);
        }
        if (m < r) {
            update(i << 1 | 1, l, r, v);
        }
        pull(i);
    }

    public static long query(int i, int l, int r) {
        if (l <= tr[i].l && tr[i].r <= r) {
            return tr[i].val;
        }
        push(i);
        int m = tr[i].l + tr[i].r >> 1;
        long res = Long.MIN_VALUE;
        if (l <= m) {
            res = query(i << 1, l, r);
        }
        if (m < r) {
            res = Math.max(res, query(i << 1 | 1, l, r));
        }
        return res;
    }

    public static void pull(int i) {
        tr[i].val = Math.max(tr[i << 1].val, tr[i << 1 | 1].val);
    }

    public static void push(int i) {
        int l = i << 1;
        int r = l | 1;
        //修改
        if (tr[i].tag) {
            updateLazy(l, tr[i].update);
            updateLazy(r, tr[i].update);
            tr[i].tag = false;
        }
        //增加
        if (tr[i].add != 0) {
            addLazy(l, tr[i].add);
            addLazy(r, tr[i].add);
            tr[i].add = 0;
        }
    }

    public static void addLazy(int i, long v) {
        tr[i].val += v;
        tr[i].add += v;
    }

    public static void updateLazy(int i, long v) {
        tr[i].val = v;
        tr[i].update = v;
        tr[i].tag = true;
        tr[i].add = 0;
    }

    static class Node {
        int l, r, len;
        long val, add, update;
        boolean tag;

        public Node(int l, int r) {
            this.l = l;
            this.r = r;
            len = r - l + 1;
        }
    }

    static class Reader2 {
        static StreamTokenizer in = new StreamTokenizer(new BufferedInputStream(System.in));
        static PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));

        public Reader2(Object... o) {
        }

        public int nextInt() {
            try {
                in.nextToken();
            } catch (Exception ignored) {
            }
            return (int) in.nval;
        }
    }
}
